﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework.Media;
using System.Xml;
using Microsoft.Xna.Framework.Content;

namespace MenuGame2DXNA
{
    public class MusicManager : InvisibleGameEntity
    {
        static List<String> ListNameMusic;
        static List<Song> ListMusic;
        static int nObjectInvisible;
        public static bool Enable{get;set;}
        public MusicManager()
        {
            ListMusic = new List<Song>();
            ListNameMusic = new List<String>();
            Enable = true;
        }
        public override void LoadContent(ContentManager content)
        {
            XmlDocument MusicXml = new XmlDocument();
            MusicXml.Load("Musics.xml");
            XmlElement root = (XmlElement)MusicXml.SelectSingleNode("Musics");
           
            foreach (XmlElement xe in root.ChildNodes)
            {
                Song temp = content.Load<Song>("Audio/" + xe.InnerText);
                ListNameMusic.Add(xe.InnerText);
                ListMusic.Add(temp);
            }
            nObjectInvisible = ListMusic.Count;
            MediaPlayer.IsRepeating = true;
        }
         public static void Play(String NameMusic)
        {
            if(Enable)
            {
                for (int i = 0; i < nObjectInvisible;i++ )
                {
                    if (ListNameMusic[i] == NameMusic)
                    {
                        MediaPlayer.Volume = 0.5f;
                        MediaPlayer.Play(ListMusic[i]);
                        break;
                    }
                }
                 
                
            }
        }
    }
}
